Page({
  data: {
    userScore: 0,
    scoreLogs: [], // 积分明细
    rules: [
      '每日打卡 +1 积分',
      '补卡消耗 10 积分',
      '取消打卡，-1 积分',
      '积分不可转让，不可提现'

    ]
  },
  onLoad() {
    const userId = wx.getStorageSync('userId');
    if (userId) {
      // 获取当前积分
      wx.request({
        url: 'http://127.0.0.1:3001/getUserScore',
        method: 'GET',
        data: { userId },
        success: (res) => {
          if (res.data && typeof res.data.score !== 'undefined') {
            this.setData({ userScore: res.data.score });
          }
        }
      });
      // 获取积分明细
      wx.request({
        url: 'http://127.0.0.1:3001/getUserScoreLogs',
        method: 'GET',
        data: { userId },
        success: (res) => {
          if (res.data && res.data.success) {
            this.setData({ scoreLogs: res.data.logs });
          }
        }
      });
    } else {
      this.setData({
        scoreLogs: [
          { type: '打卡', score: '+1', desc: '每日打卡', time: '2025-06-09 10:00:00' },
          { type: '补卡', score: '-10', desc: '补卡消耗', time: '2025-06-08 09:00:00' }
        ]
      });
    }
  }
}); 